package com.ahm.service;

import com.ahm.base.BaseService;
import com.ahm.bean.Module;
import com.ahm.dto.TreeNode;
import com.ahm.mapper.ModuleMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*功能描述
 * @author ahm
 */
@Service
public class ModuleService extends BaseService<Module,Integer> {
    @Resource
    private ModuleMapper moduleMapper;


    public List<TreeNode> findAllModules(){
       return moduleMapper.selectAllModules();
    }

    public List<TreeNode> findAllModules2(Integer roleId) {

        // 查询所有模块
        List<TreeNode> allModules = moduleMapper.selectAllModules();
        // 根据角色id 查询所有的 mid permission中查询
        List<Integer> mids = moduleMapper.selectModuleIdByRoleId(roleId);
        // 遍历所有模块
        for (TreeNode treeNode :allModules){
            if (mids.contains(treeNode.getId())){
                treeNode.setSelected(true);
            }
        }
        // 如果 tempmids 中包含模块 则 将其设为选中状态
        return allModules;





    }


}
